package com.nuoniu.sibanyun.service.crm.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nuoniu.sibanyun.entity.crm.CrmShareConfig;
import com.nuoniu.sibanyun.mapper.crm.CrmShareConfigMapper;
import com.nuoniu.sibanyun.service.crm.ICrmShareConfigService;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 分享管理 服务实现类
 * </p>
 *
 * @author 小啊刚
 * @since 2021-09-22
 */
@Service
public class CrmShareConfigServiceImpl extends ServiceImpl<CrmShareConfigMapper, CrmShareConfig> implements ICrmShareConfigService {

    @Override
    public List<CrmShareConfig> getList(Integer status) {
        if(status != null) {
            QueryWrapper wrapper = new QueryWrapper();
            wrapper.eq("status", status);
            return list(wrapper);
        }
        return list();
    }

    @Override
    public void saveShare(CrmShareConfig shareConfig) {
//        if(shareConfig.getStatus() != null && shareConfig.getStatus().equals(0)) {
//            UpdateWrapper wrapper = new UpdateWrapper();
//            wrapper.set("status", 2);
//            update(wrapper);
//        }
        saveOrUpdate(shareConfig);
    }

    @Override
    @Async
    public void countShare(Integer id) {
        CrmShareConfig config = this.getById(id);
        config.setShareCount(config.getShareCount() + 1);
        this.updateById(config);
    }
}
